package com.szly.phm.common.entity.result;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class RootResponse<T> {

    @ApiModelProperty(value = "返回的状态码")
    private String code = "";
    @ApiModelProperty(value = "返回的状态码")
    private String newToken = "";
    @ApiModelProperty(value = "返回的消息")
    private String message = "";
    @ApiModelProperty(value = "返回结果")
    private T data;

    public static <T> RootResponse success(T data) {
        var jsonResult = new RootResponse<T>();
        jsonResult.setCode(CodeStatusEnum.SUCCESS.getCode());
        jsonResult.setMessage(CodeStatusEnum.SUCCESS.getMessage());
        jsonResult.setData(data);
        return jsonResult;
    }

    public static <T> RootResponse success() {
        var jsonResult = new RootResponse<T>();
        jsonResult.setCode(CodeStatusEnum.SUCCESS.getCode());
        jsonResult.setMessage(CodeStatusEnum.SUCCESS.getMessage());
        return jsonResult;
    }

    public static RootResponse error() {
        var jsonResult = new RootResponse<>();
        jsonResult.setCode(CodeStatusEnum.FAIL.getCode());
        jsonResult.setMessage(CodeStatusEnum.FAIL.getMessage());
        return jsonResult;
    }

    public static RootResponse error(CodeStatusEnum codeStatus) {
        var jsonResult = new RootResponse<>();
        jsonResult.setCode(codeStatus.getCode());
        jsonResult.setMessage(codeStatus.getMessage());
        return jsonResult;
    }

    public static RootResponse error(String code, String message) {
        var jsonResult = new RootResponse<>();
        jsonResult.setCode(code);
        jsonResult.setMessage(message);
        return jsonResult;
    }

    public static <T> RootResponse error(T data) {
        var jsonResult = new RootResponse<T>();
        jsonResult.setCode(CodeStatusEnum.FAIL.getCode());
        jsonResult.setMessage(CodeStatusEnum.FAIL.getMessage());
        jsonResult.setData(data);
        return jsonResult;
    }

    public static <T> RootResponse success(String code, String message,T data) {
        var jsonResult = new RootResponse<>();
        jsonResult.setCode(code);
        jsonResult.setMessage(message);
        jsonResult.setData(data);
        return jsonResult;
    }

}
